package com.splic.api.controller.product;

import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.ResponseObj;
import com.splic.common.utils.StringUtils;
import com.splic.product.domain.Goods;
import com.splic.product.domain.GoodsType;
import com.splic.product.domain.Product;
import com.splic.product.service.GoodsService;
import com.splic.product.service.GoodsTypeService;
import com.splic.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/goods")
@Slf4j
public class ApiGoodsController extends BaseController {

    @Autowired
    private GoodsService goodsServiceImpl;
    @Autowired
    private GoodsTypeService goodsTypeServiceImpl;
    @Autowired
    private ProductService productServiceImpl;

    /**
     * 查询商品类型列表
     *
     * @return
     */
    @GetMapping("/getGoodsTypeList")
    public ResponseObj<List<GoodsType>> getGoodsTypeList(String packageKey) {
        try{
            List<GoodsType> list = goodsTypeServiceImpl.getGoodsTypeList(packageKey);
            return ResponseObj.SUCCESS(list);
        }catch (Exception e){
            log.error("查询服务数据失败:{}",e);
            return ResponseObj.ERROR("查询不到对应服务。");
        }
    }
    /**
     * 查询商品列表
     *
     * @return
     */
    @GetMapping("/getGoodsList")
    public ResponseObj<List<Goods>> getGoodsList(String packageKey) {
        try{
            List<Goods> list = goodsServiceImpl.getGoodsList(packageKey);
            return ResponseObj.SUCCESS(list);
        }catch (Exception e){
            log.error("查询服务套餐数据失败:{}",e);
            return ResponseObj.ERROR("获取服务套餐列表失败。");
        }
    }
}
